<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "role_access".
 *
 * @property integer $id
 * @property string $module
 * @property string $action
 * @property integer $role_id
 */
class RoleAccess extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'role_access';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['module', 'action'], 'required'],
            [['role_id'], 'integer'],
            [['module', 'action'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'module' => 'Module',
            'action' => 'Action',
            'role_id' => 'Role ID',
        ];
    }
    
    public function search_role_module($role_id , $module = '')
    {
    	$exist = RoleAccess::find()->where(['role_id' =>$role_id,'module' => $module])->exists();
    	
    	if($exist)
    	{
    		return true;
    	}else{
    		return false;
    	}
    }
    
    public function search_role_action($role_id , $module = '' , $action = '')
    {
    	
    	 $exist = RoleAccess::find()->where(['role_id' =>$role_id,'module' => $module,'action' => $action])->exists();
        
    	 if($exist)
    	 {
    	 	return true;
    	 }else{
    	 	return false;
    	 }
    }
}
